package cn.wolfcode.luowowo.acticle.service.impl;

import cn.wolfcode.luowowo.acticle.domain.Destination;
import cn.wolfcode.luowowo.acticle.domain.StrategyCommend;
import cn.wolfcode.luowowo.acticle.domain.StrategyDetail;
import cn.wolfcode.luowowo.acticle.mapper.StrategyCommendMapper;
import cn.wolfcode.luowowo.acticle.mapper.StrategyDetailMapper;
import cn.wolfcode.luowowo.acticle.query.StrategyCommendQueryObject;
import cn.wolfcode.luowowo.acticle.service.IStrategyCommendService;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * 攻略推荐服务实现类
 */
@Service
public class StrategyCommendServiceImpl implements IStrategyCommendService {
    @Autowired
    private StrategyCommendMapper strategyCommendMapper;
    @Autowired
    private StrategyDetailMapper strategyDetailMapper;
    //查询所有攻略推荐
    @Override
    public PageInfo query(StrategyCommendQueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize());
        List<StrategyCommend> list = strategyCommendMapper.selectForList(qo);
        return new PageInfo(list);
    }

    //删除攻略推荐
    @Override
    public void delete(Long id) {
        strategyCommendMapper.deleteByPrimaryKey(id);
    }
    //保存/更新
    @Override
    public void saveOrUpdate(StrategyCommend strategyCommend) {
        StrategyDetail strategyDetail = strategyDetailMapper.selectByPrimaryKey(strategyCommend.getDetail().getId());
        if(strategyCommend.getId() != null){
            strategyCommendMapper.updateByPrimaryKey(strategyCommend);
        }else{
            strategyCommendMapper.insert(strategyCommend);
        }
    }
    //查询所有攻略推荐
    @Override
    public List<StrategyCommend> list() {
        return strategyCommendMapper.selectAll();
    }

    //查询排序前5的推荐攻略
    public List<StrategyCommend> getCommentTop5() {
        return strategyCommendMapper.selectCommentTop5();
    }

}
